// pages/activity/getGift.js
import md5 from '../../utils/md5.js';
const app = getApp()
Page({
  data: {
    resourceDomain: app.resourceDomain,
    num:0
  },
  onLoad: function (options) {
    var that = this
        app.request(app.apiDomain + 'index.php?c=user&a=orderdetail', {
            order_no: options.order_no,
            user_id: options.user_id
        }, res => {
            console.log(res)
            that.setData({
                data: res.data.data,
                order_no: options.order_no,
                user_id: options.user_id,
                address:app.address
            })
        })
  },
  step_click() {
    wx.chooseAddress({
        success: (res) => {
            console.log(res)
            app.address = res;
            this.setData({
                address: res
            })
        },
        fail: function(err) {
            console.log(err)
        }
    })
},
  switchBg(e){
      console.log(e);
    this.setData({
        num: e.target.dataset.num
    })
  },
  pickGoods(){
      var that = this
    // 如果没有地址,提示填写地址
    if(!this.data.address.userName){
        wx.showToast({
            title: '请填写地址',
            icon: 'none',
            duration: 2000
        })
        return false
    }
    var time = Date.parse(new Date()).toString();
            time = time.substr(0,10);
        var obj={
            time: time,
            f_channel: 'xiaochengxu',
            goods_id : that.data.data.goods_info.id,
            order_no: that.data.order_no,
            user_id: that.data.user_id,
            sku: that.data.num,
            truename: that.data.address.userName,
            mobile: that.data.address.telNumber,
            // address: (that.data.address.provinceName+that.data.address.cityName+that.data.address.countyName+that.data.address.detailInfo).replace(/(^\s*)|(\s*$)/g, ""),
            openid: wx.getStorageSync('openid')
        }
        obj.sign = app.sign(obj);
        obj.address = (that.data.address.provinceName+that.data.address.cityName+that.data.address.countyName+that.data.address.detailInfo).replace(/(^\s*)|(\s*$)/g, "")
        console.log(obj);
    // sign = md5(time+data.goods_info.id+that.data.order_no+that.data.userId+that.data.num+that.data.address.userName+that.data.address.telNumber+that.data.address.provinceName+that.data.address.countyName+that.data.address.detailInfo+'6723d2909ec9fbf969c000e32ff2f514')
    app.request(app.apiDomain+'index.php?c=mall&a=draw',obj,res=>{
        console.log(res)
        if(res.data.status==1){
            // 成功 跳转到列表页
            wx.reLaunch({
                url: '../Order/list'
            })
        }else{
            wx.showToast({
                title: res.data.info,
                icon: 'none',
                duration: 2000
              })
        }
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})